package com.hy.doubleCompete.Two131;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * User:Mr.Du
 * Date:2024/5/25
 * Time:23:41
 */
public class QueryResults {

    public int[] queryResults(int limit, int[][] queries) {
        int m = queries.length, n = queries[0].length;
        int[] res = new int[m];
        res[0] = 1;
        Map<Integer, Integer> mpK = new HashMap<>();
        Map<Integer, Integer> mpV = new HashMap<>();
        mpK.put(queries[0][0], queries[0][1]);
        mpV.put(queries[0][1], queries[0][0]);
        for(int i = 1;i < m;i++){
            int x = queries[i][0], y = queries[i][1];
            if(mpK.containsKey(x) && mpV.containsKey(y)){
                res[i] = res[i-1];
            }else if(mpK.containsKey(x) && !mpV.containsKey(y)){
                res[i] = res[i-1];
                mpV.remove(mpK.get(x));
            }else if(!mpK.containsKey(x) && mpV.containsKey(y)){
                res[i] = res[i-1];
            }else if(!mpK.containsKey(x) && !mpV.containsKey(y)){
                res[i] = res[i-1]+1;
            }
            mpK.put(x, y);
            mpV.put(y, x);
        }
        return res;
    }

    public static void main(String[] args) {
        QueryResults queryResults = new QueryResults();
        int[] res = queryResults.queryResults(4, new int[][]{{0, 1}, {1, 2}, {2, 2}, {3, 4}, {4, 5}});
        System.out.println(Arrays.toString(res));
    }
}
